/**
 * 付款申请单
 */

app.controller('btnCtrl', ['$scope', '$http', BtnController]);
function BtnController($scope, $http){
	var gridId = $scope.gridId;
	
	$scope.bindBtn = function(event) {
		switch(event){
			case 'event-to-add': // 新增
			{
				$scope.subGrid.sonlist.push({
					id: "",
					vgsbm : "",
					vgsjc : "",
					transactionTypeBid : "",
					vremark : "",
					paymentAmount : "0",
					partnerBankInfoId : "",
					vid : "",
					partnerName : "",
					vkhh : "",
					vyhzh : "",
					remark : "",
					annexFile : "0个附件",
					receiptAnnexFile : "0个附件",
				});
				break;
			}
			case 'event-to-delete': // 删除
			{
				$scope.subGrid.deleteBatch();
				break;
			}
		};
	}
}



app.controller('formSelfCtrl', ['$scope', '$http', FormSelfController]);
function FormSelfController($scope, $http){

	//监听子表数字输入框变更
	$scope.subGrid.numberChange = function(row, field) {
		if (field == 'paymentAmount') {

			//计算总金额
			var paymentAmount = 0 ;
			if($scope.subGrid.sonlist!=null && $scope.subGrid.sonlist.length>0){
				for(var i=0;i<$scope.subGrid.sonlist.length;i++){
					if($scope.subGrid.sonlist[i].paymentAmount){
						paymentAmount = paymentAmount+parseFloat($scope.subGrid.sonlist[i].paymentAmount);
					}
				}
			}

			//回填
			$scope.valueMap['paymentAmountTotal'] = paymentAmount.toFixed(2);
		}
	}


}
